import {
  getTechnologyListByCrossShop as getMesTechnologyList,
  getTechnologyTypeList as getMesTechnologyTechnologyTypeList,
  getTechnologyStatusList as getMesTechnologyTechnologyStatusList
} from "@/api/order/mesTechnology"
import { getYesOrNotList } from "@/api/process/mesProcess"

export const mesTechnologyDialog = {
  data () {
    return {
      mesTechnologyDialogVisible: false, //表格弹框隐藏显示
      getMesTechnologyList, // 获取弹框数据接口
      hasMesTechnologyFooter: true, // 是否需要底部按钮默认true
      mesTechnologySearchDialog: {
        inline: true,
        formDesc: {
        }
      },
      mesTechnologyDialogColumn: [
        {
          type: "selection"
        },
        {
          type: "index",
          label: $i18n.t("common.order"),
          fixed: "left",
          width: 60
        },
        {
          prop: "technologyCode",
          label: $i18n.t("mesProdOrder.technologyCode"),
          showOverflowTooltip: true,
          minWidth: 130
        },
        {
          prop: "technologyName",
          label: $i18n.t("mesProdOrder.technologyName"),
          showOverflowTooltip: true,
          width: 140
        },
        {
          prop: "isDefaultTechnology",
          label: $i18n.t("mesProdOrder.isDefaultTechnology"),
          minWidth: 160,
          showOverflowTooltip: true,
          require: true,
          optionProp: {
            value: "value",
            label: "description"
          },
          option: async (data) => {
            const list = await getYesOrNotList()
            return list.data.result
          }
        },
        {
          prop: "processNum",
          label: $i18n.t("mesProdOrder.processNum"),
          minWidth: 80,
          showOverflowTooltip: true
        },
        {
          prop: "workshopName",
          label: $i18n.t("mesProdOrder.workShop"),
          minWidth: 200,
          showOverflowTooltip: true
        },
        {
          prop: "technologyType",
          label: $i18n.t("mesProdOrder.technologyType"),
          showOverflowTooltip: true,
          optionProp: {
            value: "value",
            label: "description"
          },
          option: async (data) => {
            const list = await getMesTechnologyTechnologyTypeList()
            return list.data.result
          },
          minWidth: 130
        },
        {
          prop: "prodCodeStr",
          label: $i18n.t("mesProdOrder.prodCode"),
          minWidth: 180,
          showOverflowTooltip: true
        },
        {
          prop: "prodNameStr",
          label: $i18n.t("mesProdOrder.prodName"),
          minWidth: 180,
          showOverflowTooltip: true
        },
        {
          prop: "versionNumber",
          label: $i18n.t("mesProdOrder.versionNo"),
          showOverflowTooltip: true,
          width: 140
        },
        {
          prop: "technologyStatus",
          label: $i18n.t("mesProdOrder.technologyStatus"),
          showOverflowTooltip: true,
          optionProp: {
            value: "value",
            label: "description"
          },
          option: async (data) => {
            const list = await getMesTechnologyTechnologyStatusList()
            return list.data.result
          }
        },
        {
          prop: "Remark",
          label: $i18n.t("common.remark"),
          showOverflowTooltip: true,
          minWidth: 130
        },
        {
          prop: "createByName",
          label: $i18n.t("common.createByName"),
          width: 140,
          showOverflowTooltip: true
        },
        {
          prop: "createTime",
          label: $i18n.t("common.createTime"),
          width: 160
        },
        {
          prop: "updateByName",
          label: $i18n.t("common.updateByName"),
          width: 140,
          showOverflowTooltip: true
        },
        {
          prop: "updateTime",
          label: $i18n.t("common.updateTime"),
          width: 160
        }
      ]
    }
  },
  methods: {
    transFormdatas (data) {
      return Promise.resolve({
        records: data.data.result,
        total: 0
      })
    },

    // 弹框表格，双击表格，或者点击确定 返回选中数据
    getSelectMesTechnology (data) {
      // 调试完成记得删除控制台打印
      console.log("选中数据", data)
      // 这里可以自定义返回字段信息
      // 第一个入参为当前表单绑定的对象，第二个入参为要修改的字段名，第三个入参为选中数据中相应信息
      this.$set(this.formDataDialog, "technologyId", data[0].id)
      this.$set(this.formDataDialog, "technologyCode", data[0].technologyCode)
      this.$set(this.formDataDialog, "technologyName", data[0].technologyName)
      this.$set(this.formDataDialog, "versionNumber", data[0].versionNumber)
    }
  }
}
